const send = require("koa-send")
const Router = require('koa-router')

const testRouter = new Router()
testRouter.prefix('/test')

testRouter.get('/msg', ctx => {
  const { id } = ctx.request.query
  ctx.body = {
    code: 20000,
    data: [{ id, content: 'hello' }],
    msg: '[get] something'
  }
})

testRouter.post('/data', ctx => {
  const { id } = ctx.request.body
  ctx.body = {
    code: 20000,
    data: { id, content: 'hello' },
    msg: '[post] something'
  }
})

testRouter.get('/file/download:name', ctx => {
  const name = ctx.params.name;
  const path = `static/${name}`;
  ctx.attachment(path);
  await send(ctx, path);
})

module.exports = testRouter
